{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Save project before running this\n",
    "aprx = arcpy.mp.ArcGISProject(\"CURRENT\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0: Map\n"
     ]
    }
   ],
   "source": [
    "# Show list of maps\n",
    "aprx.listMaps()\n",
    "i=0\n",
    "for mp in aprx.listMaps():\n",
    "    print( str(i)+\": \"+mp.name)\n",
    "    i=i+1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Select the Map you want to work with \n",
    "Select = 0\n",
    "mpr = aprx.listMaps()[Select]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0: Depth (High)\n",
      "1: Depth (Low)\n",
      "2: Depth (Medium)\n",
      "3: Velocity (High)\n",
      "4: Velocity (Low)\n",
      "5: Velocity (Medium)\n",
      "6: WSE (High)\n",
      "7: WSE (Low)\n",
      "8: WSE (Medium)\n",
      "9: Ground Elevation\n",
      "10: World Hillshade\n",
      "11: World Topographic Map\n"
     ]
    }
   ],
   "source": [
    "# Show list of Layers\n",
    "i=0\n",
    "for m in mpr.listLayers():\n",
    "    print( str(i) + \": \"+ m.name )\n",
    "    i=i+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Select the boundaries of the layers to be changed\n",
    "unvis0 = 0\n",
    "unvis1 = 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0: Velocity\n",
      "1: WSE\n",
      "2: Depth\n"
     ]
    }
   ],
   "source": [
    "# Show list of layouts\n",
    "aprx.listLayouts()\n",
    "i=0\n",
    "for ly in aprx.listLayouts():\n",
    "    print(str(i)+\": \"+ly.name)\n",
    "    i=i+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Don't change anything in this function unless you know what are you doing\n",
    "# But run the cell to define the function\n",
    "def onlyvis(mpr,novis0,novis1,vis):\n",
    "    # Makes everything invisible from novis0 to novis1 then makes vis visible in the mpr map\n",
    "    i=novis0\n",
    "    for m in mpr.listLayers()[novis0:novis1]:\n",
    "        m.visible = False\n",
    "        if (novis0==vis):\n",
    "            print( str(i)+\": \"+m.name)\n",
    "        i=i+1\n",
    "\n",
    "    mpr.listLayers()[vis].visible = True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Fill the list with the saving path, must be a raw string define as r\"STRING\"\n",
    "# Remember it must match the position shown on cell 6.\n",
    "pathto = [\n",
    "    r\"C:\\temp\\DPT_High.png\",\n",
    "    r\"C:\\temp\\DPT_Low-.png\",\n",
    "    r\"C:\\temp\\DPT_Medi.png\",\n",
    "    r\"C:\\temp\\VEL_High.png\",\n",
    "    r\"C:\\temp\\VEL_Low-.png\",\n",
    "    r\"C:\\temp\\VEL_Medi.png\",\n",
    "    r\"C:\\temp\\WSE_High.png\",\n",
    "    r\"C:\\temp\\WSE_Low-.png\",\n",
    "    r\"C:\\temp\\WSE_Medi.png\"\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a vector with what layout each variable will be using\n",
    "# In this example 0 is Velocity, 1 is WSE and 2 is Depth as per cell 8.\n",
    "# It must match the position of the cell 6\n",
    "\n",
    "layoutsel = [0,0,0,2,2,2,1,1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0: Depth (High)\n",
      "1: Depth (Low)\n",
      "2: Depth (Medium)\n",
      "3: Velocity (High)\n",
      "4: Velocity (Low)\n",
      "5: Velocity (Medium)\n",
      "6: WSE (High)\n",
      "7: WSE (Low)\n",
      "8: WSE (Medium)\n",
      "Exporting : 0 : C:\\temp\\DPT_High.png\n",
      "Exporting : 1 : C:\\temp\\DPT_Low-.png\n",
      "Exporting : 2 : C:\\temp\\DPT_Medi.png\n",
      "Exporting : 3 : C:\\temp\\VEL_High.png\n",
      "Exporting : 4 : C:\\temp\\VEL_Low-.png\n",
      "Exporting : 5 : C:\\temp\\VEL_Medi.png\n",
      "Exporting : 6 : C:\\temp\\WSE_High.png\n",
      "Exporting : 7 : C:\\temp\\WSE_Low-.png\n",
      "Exporting : 8 : C:\\temp\\WSE_Medi.png\n",
      "FINISHED\n"
     ]
    }
   ],
   "source": [
    "for j in range(len(layoutsel)):\n",
    "    # Select layout from layoutsel\n",
    "    lyd = aprx.listLayouts()[layoutsel[j]]\n",
    "    exppath = pathto[j]\n",
    "    # Change map to only visible\n",
    "    onlyvis(mpr,unvis0,unvis1+1,j+unvis0)\n",
    "    # Export\n",
    "    print(\"Exporting : \"+str(j)+\" : \"+exppath)\n",
    "    lyd.exportToPNG(exppath,resolution = 300)\n",
    "print(\"FINISHED\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ArcGISPro",
   "language": "Python",
   "name": "python3"
  },
  "language_info": {
   "file_extension": ".py",
   "name": "python",
   "version": "3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
